﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

namespace WxPayAPI
{
    public partial class OrderQueryPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string out_trade_no = Request.QueryString["out_trade_no"];
            string result = OrderQuery.Run("", out_trade_no);//调用订单查询业务逻辑 
            Regex rx_trade_state = new Regex(@"<br>trade_state=[a-zA-Z]*?<br>");
            Regex rx1_trade_state_desc = new Regex(@"<br>trade_state_desc=.*?<br>");
            Match match_rx_trade_state = rx_trade_state.Match(result);
            Match match_rx1_trade_state_desc = rx1_trade_state_desc.Match(result);
            string desc = "";
            if (!string.IsNullOrEmpty(match_rx1_trade_state_desc.Value))
            {
                try
                {
                    desc = match_rx1_trade_state_desc.Value.Replace("<br>", "").Split('=')[1];
                }
                catch (Exception ex)
                {
                    desc = "";
                }
            
            }
            string status = "";
            if (!string.IsNullOrEmpty(match_rx_trade_state.Value))
            {
                try
                {
                    status = match_rx_trade_state.Value.Replace("<br>", "").Split('=')[1];
                }
                catch (Exception ex)
                {
                    status = "";
                }

            }

            Response.Write("{\"trade_state\":\"" + status + "\",\"trade_state_desc\":\"" + desc + "\"}");
            Response.End();            
        }  
    }
}
